<div class="panel">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名:</label>
            <div class="layui-input-block">
                <input  type="text" name="username" placeholder="请输入旧密码" lay-verify="title" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">旧密码:</label>
            <div class="layui-input-block">
                <input  type="password" name="oldpwd" placeholder="请输入旧密码" lay-verify="title" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码:</label>
            <div class="layui-input-block">
                <input  type="password" name="newpwd" placeholder="请输入新密码" lay-verify="title" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">再密码:</label>
            <div class="layui-input-block">
                <input  type="password" name="confirmpwd" placeholder="请再次输入密码" lay-verify="title" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn btn_edit_pwd_save">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
    $.getJSON('AccountData.json',function (data) {
        $("input[name='username']").val(data["admin_name"]);
    });
    $(".btn_edit_pwd_save").click(function () {
        var oldpwd = $("input[name='oldpwd']").val()
            ,newpwd = $("input[name='newpwd']").val()
            ,confirmpwd = $("input[name='confirmpwd']").val()
            ,username = $("input[name='username']").val();
        if(username !="" && oldpwd != "" && newpwd != "" && confirmpwd != ""){
            if(newpwd == confirmpwd){
                $.ajax({
                    type:"get"
                    ,url:"UpdateAdmin"
                    ,data:{
                        name : username
                        ,pwd : newpwd
                        ,oldpwd :oldpwd
                    }
                    ,success:function (result) {
                        if(result){
                            alert("修改成功");
                            location.reload();
                            layer.closeAll();
                        }else {
                            alert("修改失败");
                        }
                    }
                });
            }else {
                alert("两次输入密码不一致");
            }
        }else {
            alert("请填写完整信息");
        }
    });
</script>